﻿
CREATE FUNCTION dbo.HTMLEncode
	(
	@HTML varchar(8000)
	)
RETURNS varchar(8000)
AS
BEGIN

DECLARE @Char char(1),@Entity varchar(10)

SELECT TOP 1 @Char = Character,@Entity = Entity FROM  ts_Encoding_ISO ORDER BY Character

WHILE @@ROWCOUNT > 0 BEGIN
	
	SET @HTML = REPLACE(@HTML,@Char,@Entity)
	
	SELECT TOP 1 @Char = Character,@Entity = Entity FROM  ts_Encoding_ISO WHERE Character > @Char ORDER BY Character

END

RETURN @HTML
END

